package com.sxm.yiwei.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.sxm.yiwei.R;
import com.sxm.yiwei.activitis.MineMsgHead;
import com.sxm.yiwei.activitis.MsgLookActivity;
import com.sxm.yiwei.beans.Look;
import com.sxm.yiwei.tools.CastTime;
import com.sxm.yiwei.tools.CircleTransform;
import com.sxm.yiwei.utils.InternetAddressUtis;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * Created by KuKa on 2017/7/28.
 * 看过我的 列表
 */

public class LookAdapter extends BaseAdapter {
    Context context;
    public List<Look.DataBean> list;
    public LookAdapter(Context context, List<Look.DataBean> list) {
        this.list=list;
        this.context=context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View v;
        ViewHolder h;
        if (convertView==null){
            v = View.inflate(context, R.layout.loonk_item,null);
            h = new ViewHolder();
            h.delete = (TextView) v.findViewById(R.id.look_itemdelete);
            h.name = (TextView) v.findViewById(R.id.look_itemname);
            h.img = (ImageView) v.findViewById(R.id.look_itemimg);
            h.people = (TextView) v.findViewById(R.id.look_itempeople);
            h.time = (TextView) v.findViewById(R.id.look_itemtime);
            v.setTag(h);

        }else {
            v = convertView;
            h = (ViewHolder) v.getTag();
        }
        h.time.setText(CastTime.CastTime(list.get(position).getUpdateTime()));
        h.name.setText(list.get(position).getNickname());
        h.people.setText(list.get(position).getCount()+"");
        ImageOptions o = new ImageOptions.Builder().setCircular(true).build();
        Picasso.with(context).load(InternetAddressUtis.IMG_URL+ list.get(position).getAvatar()).error(R.mipmap.morentouxiang).transform(new CircleTransform()).into(h.img);

        h.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickDelete!=null){
                    onClickDelete.OnDelete(position);
                }
            }
        });
        notifyDataSetChanged();
        return v;
    }
    class ViewHolder{
        ImageView img;
        TextView name,time,people,delete;
    }
    OnClickDelete onClickDelete;
    public interface  OnClickDelete{
        void OnDelete(int p);
    }
    public void setOnClickDelete(OnClickDelete onClickDelete){
        this.onClickDelete=onClickDelete;

    }
}
